<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>登录</title>
	<link href="__PUBLIC__/css/default/index.css" rel="stylesheet" />
	<link href="__PUBLIC__/css/default/global.css?v=1" rel="stylesheet" />


	<script src="__JS__/jquery.min.js"></script>
	<link rel="stylesheet" href="__PUBLIC__/js/layer/layer.css" />
	<script src="__PUBLIC__/js/layer/layer.js"></script>


	<link rel="stylesheet" href="__CSS__/bootstrap.min.css">
	<link rel="stylesheet" href="__CSS__/font-awesome.min.css">
	<link rel="stylesheet" href="__CSS__/main.css">
	<link rel="stylesheet" href="__CSS__/animate.css">
	<link rel="stylesheet" href="__CSS__/responsive.css">


</head>
<body onkeydown="KeyDown();" style="background-color: #f2f6fa;">
<header>
	<div class="container">
		<div class="row">
			<div class="col-md-3 col-xs-6 col-sm-3">
				<a href="/?/explore/index/" class="logo">
					<img src="__IMG__/logo.png" alt="">
				</a>
			</div>


		</div>
	</div>
</header>

<br/>
<br/>
<br/>

<div class="content">
	<div class="logo_content">
		<div class="login_tab">
			<span class="login_accounts active">手机密码登录</span>
			<span class="login_accounts" style="display: none;">二维码登录</span>
		</div>
		<div class="login-if">
			<div class="input_main">
				<div class="input_phone">
					<span class="left_it"><img src="__IMG__/mphoneicon.png" alt="">手机号：</span>
					<span class="input_tt"><input type="text" name="phone" id="phonenum" placeholder="请输入手机号"></span>
				</div>
				<div class="input_phone">
					<span class="left_it"><img src="__IMG__/paswdicon.png" alt="">密&nbsp;&nbsp;&nbsp;&nbsp;码：&nbsp;</span>
					<span class="input_tt"><input type="password" id="pwd" placeholder="输入密码"></span>
				</div>
			</div>
			<div class="forget"><a href="/forget_pwd">忘记密码？</a></div>
			<div class="login_btn">
				<span class="lgbtn" id="phone_login">立即登录</span>
			</div>
			<div class="pt_tt">
				<span class="pt1">还没账号？</span>
				<a href="/register"><span class="pt2">立即注册</span></a>
			</div>
			<br/>
		</div>
		<div class="login-if hidden">
			<div class="input_main">
				<div class="input_phone">
					<span class="left_it"><img src="__IMG__/mphoneicon.png" alt="">账号：</span>
					<span class="input_tt"><input type="text" id="accountnum" placeholder="输入手机号"></span>
				</div>
				<div class="input_phone">
					<span class="left_it"><img src="__IMG__/paswdicon.png" alt="">密码：</span>
					<span class="input_tt"><input type="text" id="passwordnum" placeholder="输入密码"></span>
				</div>
			</div>
			<div class="forget"><a href="/forget_pwd">忘记密码？</a></div>
			<div class="login_btn">
				<span class="lgbtn" id="account_login">立即登录</span>
			</div>
			<div class="pt_tt">
				<span class="pt1">还没账号？</span>
				<a href=""><span class="pt2">立即注册</span></a>
			</div>
			<br/>
		</div>

	</div>

</div>

<script>
	$(function(){
		clickinit();
		$('#phone_login').click(function () {

			var phone = $('#phonenum').val();
			var code = $('#pwd').val();
			if(phone.length== 0){

				showMsg("请输入手机号");
				return false;

			}
			if(code.length== 0){

				showMsg("请输入密码");
				return false;

			}

			$.post('/login_by_phone/',{"phone":phone,"code":code},function (result) {

				if(result.code == 200){

					window.location.href = "/org_admin";
				}else{
					showMsg("账号密码错误");
				}
			},'json');

		});
	});

	function KeyDown()
	{
		if (event.keyCode == 13)
		{
			event.returnValue=false;
			event.cancel = true;
			var phone = $('#phonenum').val();
			var code = $('#pwd').val();
			if(phone.length== 0){

				showMsg("请输入手机号");
				return false;

			}
			if(code.length== 0){

				showMsg("请输入密码");
				return false;

			}

			$.post('/login_by_phone/',{"phone":phone,"code":code},function (result) {

				if(result.code == 200){

					window.location.href = "/org_admin";
				}else{
					showMsg("账号密码错误");
				}
			},'json');
		}
	}
	function clickinit(){
		$(".login_accounts").click(function(){
			$(".login_accounts").removeClass('active');
			$(this).addClass('active');
			var num=$(this).index();
			$(".login-if").addClass('hidden');
			$(".login-if").eq(num).removeClass('hidden');

		});
	}
	var wait = 60;
	var code_state = "IDLE";
	/**
	 * 发送短信验证码
	 */
	function send_code(){
		if (code_state != "IDLE"){
			return;
		}
		var tel = $.trim($("input[name='phone']").val());
		var reg = /^1[3|4|5|7|8][0-9]\d{8}$/;

		if(false == reg.test(tel)){
			showMsg('请输入正确的手机号');
			return ;
		}

		var url = "/api/user/sendCode?phone="+tel;
		$.get(url,function (result) {

			if(result.code == 200){
				code_state = "SENDING";
				count_down();
			}else if(result.code == 199){
				showMsg('注册手机号已存在');

			}else{
				showMsg('验证码发送失败');

			}
		},'json');



	}

	function count_down(){
		if(wait <= 0){
			$(".bt_cd").removeClass("active")
			$(".bt_cd").attr("onclick", "send_code()");
			$(".bt_cd").html("获取验证码");
			wait = 60;
			code_state = "IDLE";
		} else {
			$(".bt_cd").addClass("active")
			$(".bt_cd").attr("onclick", "");
			$(".bt_cd").html( "剩余" + wait + "秒");
			wait--;
			setTimeout(count_down, 1000);
		}
	}

	/**
	 * 显示消息
	 */
	function showMsg(msg,time) {
		layer.open({
			content: msg ,
			time: time ? time : 2 //3秒后自动关闭
		});
	}
</script>
</body>
</html>